const App=getApp()
Page({
  data:{
    orderId:null,
    orderDetail:null
  },
  onLoad(option){
    this.setData({
      orderId:option.orderId
    })

    App.HttpService.orderDetail({
      id: this.data.orderId
    }).then(res => {
      this.setData({
        orderDetail:res.data
      })
    })
  },
  
  // 返回
  onReturn(){
    App.WechatService.redirectTo('/pages/index/index')
  },
  // 显示订单列表
  onShowOrderList(){
    App.WechatService.redirectTo('/pages/order/index')
  },
  onPay(){
    let totalAmount=this.data.orderDetail.totalAmount
    let orderId=this.data.orderId
    let outTradeNo=this.data.orderDetail.orderCode
    App.HttpService.orderPay({
      totalFee:totalAmount,
      outTradeNo
    }).then(res=>{
      App.WechatService.requestPayment({
        timeStamp:res.timeStamp,
        nonceStr:res.nonceStr,
        package:res.package,
        signType:res.signType,
        paySign:res.paySign
      })
      .then((success)=>{
        App.WechatService.redirectTo('/pages/orderDetail/index?orderId='+orderId)
      },(error)=>{
        
      })
    })
  }
})